package com.qingzhu.dao.impl;

import com.qingzhu.dao.SpecificationDao;
import com.qingzhu.pojo.Specification;
import com.qingzhu.util.CreateSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class SpecificationDaoImpl implements SpecificationDao {

    @Override
    public Specification findById(int id) {
        try(SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)){
            SpecificationDao specificationDao = sqlSession.getMapper(SpecificationDao.class);
            return specificationDao.findById(id);
        }
    }

    @Override
    public List<Specification> findSpecificationAll() {
        try(SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)){
            SpecificationDao specificationDao = sqlSession.getMapper(SpecificationDao.class);
            return specificationDao.findSpecificationAll();
        }
    }

    @Override
    public Specification findIdFromName(String specName) {
        try(SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)){
            SpecificationDao specificationDao = sqlSession.getMapper(SpecificationDao.class);
            return specificationDao.findIdFromName(specName);
        }
    }
}
